package slap.mvc.result;

import slap.http.Header;
import slap.http.Request;
import slap.http.Response;
import slap.http.StatusCode;

/**
 * 401 Unauthorized
 */
public class Unauthorized extends Result {
    
    String realm;
    
    public Unauthorized(String realm) {
        super(realm);
        this.realm = realm;
    }

    public void apply(Request request, Response response) {
        response.status = StatusCode.UNAUTHORIZED;
        response.setHeader(Header.Names.WWW_AUTHENTICATE, "Basic realm=\"" + realm + "\"");
    }
}
